package com.banban.user.controller;

import com.alibaba.fastjson.JSONObject;
import com.banban.user.service.PromptTemplateVersionService;
import com.banban.user.service.UserPrologueService;
import com.banban.user.util.RedisUtil;
import com.banban.user.vo.DataResult;
import com.banban.user.vo.InitInfoVO;
import com.banban.user.vo.PromptTemplateVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/chat")
@Slf4j
public class ChatController {

    @Autowired
    private PromptTemplateVersionService promptTemplateVersionService;

    @Autowired
    private UserPrologueService prologueService;

    @Resource
    private RedisUtil redisUtil;

    private static final String BANBAN_SYSTEM_MESSAGE = "BANBAN_SYSTEM_MESSAGE";
    private static final String BANBAN_USER_MESSAGE = "BANBAN_USER_MESSAGE_";

    /**
     * 获取初始化信息（开场白、提示模板id）
     *
     * @return
     */
    @GetMapping("/getPrologue")
    public DataResult getPrologue() {
        log.info("获取初始化信息（开场白、提示模板id）");
        String promptTemplateId = promptTemplateVersionService.getPromptTemplateId();
        String prologue = prologueService.getPrologue();
        InitInfoVO vo = new InitInfoVO();
        vo.setPromptTemplateId(promptTemplateId);
        vo.setPrologue(prologue);
        return DataResult.success(vo);
    }


    /**
     * 设置系统消息
     * @param map
     * @return
     */
    @PostMapping("/setSystemMessage")
    public DataResult setSystemMessage(@RequestBody Map<String, String> map) {
        log.info("设置系统消息");
        redisUtil.set(BANBAN_SYSTEM_MESSAGE,map);
        return DataResult.success();
    }

    /**
     * 设置用户消息
     * @param map
     * @return
     */
    @PostMapping("/setUserMessage")
    public DataResult setUserMessage(@RequestBody Map<String, String> map) {
        log.info("设置用户消息");
        redisUtil.set(BANBAN_USER_MESSAGE+map.get("userId"),map);
        return DataResult.success();
    }

}
